import { BaseCommand } from "./BaseCommand";
import { API_EVENT, COMMAND_STATUS } from "@/FrontProcessing/interface";
/**
 * Cmd_Washer
 * @description 垫圈网格
 */
export class Cmd_Washer_Enter extends BaseCommand {
  event = API_EVENT.WASHER_ENTER;
  execute(): Promise<boolean> {
    this.system.history.push(this);
    return new Promise((resolve) => {
      this.status = COMMAND_STATUS.RUNNING;
      this.system.washer_enter().then((result) => {
        console.log("==== Cmd_Washer_Enter result: ", result);
        this.status = COMMAND_STATUS.FINISHED;
        resolve(result);
      });
    });
  }

  undo(): boolean {
    return false;
  }
}
export class Cmd_Washer_Leave extends BaseCommand {
  event = API_EVENT.WASHER_LEAVE;
  execute(): Promise<boolean> {
    this.system.history.push(this);
    return new Promise((resolve) => {
      this.status = COMMAND_STATUS.RUNNING;
      this.system.washer_leave().then((result) => {
        console.log("==== Cmd_Washer_Leave result: ", result);
        this.status = COMMAND_STATUS.FINISHED;
        resolve(result);
      });
    });
  }

  undo(): boolean {
    return false;
  }
}
export class Cmd_Washer_Select extends BaseCommand {
  event = API_EVENT.WASHER_SELECT;
  execute(): Promise<boolean> {
    this.system.history.push(this);
    return new Promise((resolve, reject) => {
      this.status = COMMAND_STATUS.RUNNING;
      this.system
        .washer_select()
        .then((result) => {
          this.status = COMMAND_STATUS.FINISHED;
          resolve(result);
        })
        .catch((err) => {
          reject(false);
        });
    });
  }

  undo(): boolean {
    return false;
  }
}
export class Cmd_Washer_Create extends BaseCommand {
  event = API_EVENT.WASHER_CREATE;
  execute(): Promise<boolean> {
    this.system.history.push(this);
    return new Promise((resolve) => {
      this.status = COMMAND_STATUS.RUNNING;
      this.system
        .washer_create({
          ...this.params,
        })
        .then((result) => {
          console.log("==== Cmd_Washer_Create result: ", result);
          this.status = COMMAND_STATUS.FINISHED;
          resolve(result);
        });
    });
  }

  undo(): boolean {
    return false;
  }
}

export class Cmd_Washer_Clear extends BaseCommand {
  event = API_EVENT.WASHER_CLEAR;
  execute(): Promise<boolean> {
    this.system.history.push(this);
    return new Promise((resolve) => {
      this.status = COMMAND_STATUS.RUNNING;
      this.system.washer_clear(this.params).then((result) => {
        this.status = COMMAND_STATUS.FINISHED;
        resolve(result);
      });
    });
  }

  undo(): boolean {
    return false;
  }
}
export class Cmd_Washer_Find extends BaseCommand {
  event = API_EVENT.WASHER_FIND;
  execute(): Promise<boolean> {
    this.system.history.push(this);
    return new Promise((resolve) => {
      this.status = COMMAND_STATUS.RUNNING;
      this.system
        .washer_find({
          ...this.params,
        })
        .then((result) => {
          console.log("---> find pin hole: ", result);
          this.status = COMMAND_STATUS.FINISHED;
          resolve(result);
        });
    });
  }

  undo(): boolean {
    return false;
  }
}
export class Cmd_Washer_Hole extends BaseCommand {
  event = API_EVENT.WASHER_HOLE;
  execute(): Promise<boolean> {
    this.system.history.push(this);
    return new Promise((resolve) => {
      this.status = COMMAND_STATUS.RUNNING;
      this.system
        .washer_hole({
          ...this.params,
        })
        .then((result) => {
          this.status = COMMAND_STATUS.FINISHED;
          resolve(result);
        });
    });
  }

  undo(): boolean {
    return false;
  }
}
